package old;
//========== Program Description ==========
//name : Tree
//propose : build a tree to save data
//Written by akkz
//=========================================

import java.util.*;

public class TreeTest
{
	public static void main(String[] args)
	{
		Scanner inputStream = new Scanner(System.in);
	
		int inputData;
		Tree head;

		
		inputData = inputStream.nextInt();
		
		head = creatHead(inputData);
		
		
		while(inputData != 0)
		{
			inputData = inputStream.nextInt();
			
			creat(inputData, head);
		}
		
		
		output(head);
	}
	
	private static Tree creatHead(int inputData)
	{
		return new Tree(inputData);
	}
	
	private static void creat(int inputData, Tree head)
	{
		if (inputData > head.getData())
		{
			if (head.getRightNode() == null)
				head.setRightNode(new Tree(inputData));
			else
				creat(inputData, head.getRightNode());
		}
		else
		{
			if (head.getLeftNode() == null)
				head.setLeftNode(new Tree(inputData));
			else
				creat(inputData, head.getLeftNode());	
		}
	}
	
	public static void output(Tree head)
	{
		if(head.getLeftNode() != null)
			output(head.getLeftNode());
			
		System.out.print(head.getData() + " ");
			
		if(head.getRightNode() != null)
			output(head.getRightNode());
	}
}

class Tree
{
	private Tree rightNode;
	private Tree leftNode;
	private int treeData;
	
	public Tree(int treeData)
	{
		this.treeData = treeData;
		this.rightNode = null;
		this.leftNode = null;
	}
	
	public void setLeftNode(Tree leftNode)
	{
		this.leftNode = leftNode;
	}
	
	public void setRightNode(Tree rightNode)
	{
		this.rightNode = rightNode;
	}
	
	public int getData()
	{
		return treeData;
	}
	
	public Tree getRightNode()
	{
		return rightNode;
	}
	
	public Tree getLeftNode()
	{
		return leftNode;
	}
}
